package xin.nick.summer.util;

import xin.nick.summer.annotation.Component;

import javax.annotation.*;
import java.lang.annotation.*;

/**
 * @author Nick
 * @date 2021/5/29
 * @description
 */
public class MyUtil {

    public static String lowerFist(String str) {
        if(str == null && str.length() == 0) {
            return str;
        }
        char[] chars = str.toCharArray();
        if('A' <= chars[0] && chars[0] <= 'Z') {
            chars[0] += 32;
        }
        return String.valueOf(chars);
    }

    public static boolean hasComponentAnnotation(Class<?> clazz) {
        Annotation[] annotations = clazz.getAnnotations();
        for (Annotation annotation : annotations) {
            if (annotation.annotationType() != Deprecated.class &&
                    annotation.annotationType() != SuppressWarnings.class &&
                    annotation.annotationType() != Override.class &&
                    annotation.annotationType() != PostConstruct.class &&
                    annotation.annotationType() != PreDestroy.class &&
                    annotation.annotationType() != Resource.class &&
                    annotation.annotationType() != Resources.class &&
                    annotation.annotationType() != Generated.class &&
                    annotation.annotationType() != Target.class &&
                    annotation.annotationType() != Retention.class &&
                    annotation.annotationType() != Documented.class &&
                    annotation.annotationType() != Inherited.class
            ) {
                if (annotation.annotationType() == Component.class){
                    return true;
                }else{
                    if(hasComponentAnnotation(annotation.annotationType())) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

}
